<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue-2.4.0.js"></script>

</head>

<body>
    <div id="app">
        <!-- 使用ref来标记组件
            用$refs.com1来获取组件对应的node，进而可以访问子组件数据调用子组件方法
         -->
        <com1 ref="com1"></com1>

        <button type="button" class="btn btn-primary" @click="enter">button</button>

    </div>
    <template id="temp1" @click="enter">
        <div>
            <h1>这是一个子组件---{{msg}}</h1>
        </div>
    </template>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {},
            methods: {
                enter() {
                    this.$refs.com1.show();
                }
            },
            components: {
                com1: {
                    template: "#temp1",
                    data: function () {
                        return {
                            msg: ""
                        }
                    },
                    methods: {
                        show() {
                            this.msg = "调用了子组件方法"
                            console.log("子组件的show方法")
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>